package cn.dnui_lf_705.dnui_16110100705.controller;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import cn.dnui_lf_705.dnui_16110100705.R;
import cn.dnui_lf_705.dnui_16110100705.bean.ResultBean;
import cn.dnui_lf_705.dnui_16110100705.listener.OnRetrofitListener;
import cn.dnui_lf_705.dnui_16110100705.model.UserModel;


public class AddCommentActivity extends BaseActivity implements OnRetrofitListener<ResultBean> {
    private EditText pinglun;
    private Button btn;
    SharedPreferences sharedPreferences;
    String user_id;
    String item_id;
    @Override
    void initViews() {
        pinglun = findViewById(R.id.liuyan);
        btn = findViewById(R.id.queding);
        sharedPreferences = getSharedPreferences("yht",Context.MODE_PRIVATE);
        user_id = sharedPreferences.getString("user_id","");
        item_id = getIntent().getStringExtra("item_id");
    }

    @Override
    void initEvents() {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
            }
        });
    }

    @Override
    void initData() {
        UserModel userModel = new UserModel();
        userModel.insertComment(item_id,pinglun.getText().toString().trim(),this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_comment);
        initViews();
        initEvents();
        if (setEnableSliding()) {
            ArActSlidLayout rootView = new ArActSlidLayout(this);
            rootView.bindActivity(this);//绑定需要窗口的布局：
        }
    }
    protected boolean setEnableSliding() {//默认返回是需要的，只需继承的时候重写次代码 true : 需要；false :不需要；
        return true;
    }



    @Override
    public void onsuccess(ResultBean resultBean, int flag) {
            if(resultBean.getSuccess().equals("0"))
            {
                showToast("评论失败");
            }
            else
            {
                showToast("评论成功");
                finish();
            }
    }

    @Override
    public void onFailure(String string) {
            showToast("添加评论失败");
    }
}
